<%@ page language="java" pageEncoding="utf-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="s" uri="http://www.springframework.org/tags" %>
<%@ page isELIgnored="false"%>
<!DOCTYPE html PUBLIC "-//W3C//Dth XHTML 1.0 Transitional//EN">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>山西煤炭现货公路交易系统客户端</title>
 <meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" name="viewport">
    <!-- Bootstrap 3.3.5 -->
    <link rel="stylesheet" href="<s:url value="/resources"/>/adminlte/bootstrap/css/bootstrap.min.css">
     <!-- daterange picker -->
    <link rel="stylesheet" href="<s:url value="/resources"/>/adminlte/plugins/daterangepicker/daterangepicker-bs3.css">
    <!-- Font Awesome -->
    <link rel="stylesheet" href="<s:url value="/resources"/>/adminlte/font-awesome/css/font-awesome.min.css">
    <!-- Ionicons -->
    <link rel="stylesheet" href="<s:url value="/resources"/>/adminlte/ionicons/css/ionicons.min.css">
    <!-- jvectormap -->
    <link rel="stylesheet" href="<s:url value="/resources"/>/adminlte/plugins/jvectormap/jquery-jvectormap-1.2.2.css">
    <!-- Theme style -->
    <link rel="stylesheet" href="<s:url value="/resources"/>/adminlte/dist/css/AdminLTE.min.css">
    <link rel="stylesheet" href="<s:url value="/resources"/>/adminlte/dist/css/skins/_all-skins.min.css">
     <!-- DataTables -->
    <link rel="stylesheet" href="<s:url value="/resources"/>/adminlte/plugins/datatables/dataTables.bootstrap.css">
    <!-- AdminLTE Skins. Choose a skin from the css/skins
         folder instead of downloading all of them to reduce the load. -->
    <link rel="stylesheet" href="<s:url value="/resources"/>/adminlte/dist/css/skins/_all-skins.min.css">
	<!-- jQuery 2.1.4 -->
    <script src="<s:url value="/resources"/>/adminlte/plugins/jQuery/jQuery-2.1.4.min.js"></script>
	<!-- Bootstrap 3.3.5 -->
    <script src="<s:url value="/resources"/>/adminlte/bootstrap/js/bootstrap.min.js"></script>
	 <!-- AdminLTE App -->
    <script src="<s:url value="/resources"/>/adminlte/dist/js/app.min.js"></script>
    <!-- Select2 -->
    <link rel="stylesheet" href="<s:url value="/resources"/>/adminlte/plugins/select2/select2.min.css">
    <!-- Theme style -->
    <link rel="stylesheet" href="<s:url value="/resources"/>/adminlte/dist/css/AdminLTE.min.css">
    
         <script src="<s:url value="/resources"/>/adminlte/default.js"></script>
      <script src="<s:url value="/resources"/>/adminlte/default_settlement.js"></script>
      
      <!-- 百度地图 -->
   <style type="text/css">
	body, html,#allmap {width: 100%;height: 100%;overflow: hidden;margin:0;font-family:"微软雅黑";}
	</style>
	<script type="text/javascript" src="http://api.map.baidu.com/library/AreaRestriction/1.2/src/AreaRestriction_min.js"></script>
	<script type="text/javascript" src="http://api.map.baidu.com/api?v=2.0&ak=pWpfYkCbEHczf7UNja4U8FbVnk99U4k8"></script>
</head>
<body class="skin-blue sidebar-mini">
<input type="hidden"  id="falseload">
<div id="allmap" style="width:100%;height: 100%;"></div>      
      <script type="text/javascript">
	// 百度地图API功能
	
	/* map.setCurrentCity("大同市");          // 设置地图显示的城市 此项是必须设置的
	var b = new BMap.Bounds(new BMap.Point(112.175012,40.047862),new BMap.Point(112.175012,40.047862));
	try {	
		BMapLib.AreaRestriction.setBounds(map, b);
	} catch (e) {
		alert(e);
	} */
	
	map = new BMap.Map("allmap",{minZoom:5,maxZoom:16});
	map.centerAndZoom(new BMap.Point(108.795963,35.634807), 6);
	//getBoundary("山西省");
	map.enableScrollWheelZoom();
	map.addControl(new BMap.MapTypeControl());   //添加地图类型控件
	map.enableScrollWheelZoom(true);     //开启鼠标滚轮缩放
	var opts;
	var id = 0;
	//loadflag(opts,id);//页面ajax加载
	cx();
	function addClickHandler(content,marker){
		marker.addEventListener("click",function(e){
			openInfo(content,e)}
		);
	}
	function openInfo(content,e){
		var p = e.target;
		var point = new BMap.Point(p.getPosition().lng, p.getPosition().lat);
		var infoWindow = new BMap.InfoWindow(content,opts);  // 创建信息窗口对象 
		map.openInfoWindow(infoWindow,point); //开启信息窗口
	}
	
	
	//添加行政区域
	/*  function getBoundary(name){       
		var bdary = new BMap.Boundary();
		bdary.get(name, function(rs){       //获取行政区域
			map.clearOverlays();        //清除地图覆盖物       
			var count = rs.boundaries.length; //行政区域的点有多少个
			if (count === 0) {
				alert('未能获取当前输入行政区域');
				return ;
			}
          	var pointArray = [];
			for (var i = 0; i < count; i++) {
				var ply = new BMap.Polygon(rs.boundaries[i], {strokeWeight: 2, strokeColor: "#ff0000"}); //建立多边形覆盖物
				map.addOverlay(ply);  //添加覆盖物
				pointArray = pointArray.concat(ply.getPath());
			}    
			map.setViewport(pointArray);    //调整视野    
		});   
	} */

	/* setTimeout(function(){
		getBoundary();
	}, 2000); */
	//ajax加载地图标志
	function loadflag(opts,id){
		$.ajax({
             type: "post",
             dataType:'text',
             data:{"id":id},
             //dataType: "json",//返回json格式的数据
             url: "<s:url value="/"/>/baidumapcontroller/loadCoalDistributionInfo",
            success: function(data){
                /* var data_info = [[113.610001,40.056699,"地址：大同县"],
					 [113.184564,40.044327,"地址：矿区"]
					]; */
					var json =eval('(' + data + ')');
					if(json[0].id!="-1"){
						opts = {
								width : 250,     // 信息窗口宽度
								height: 80,     // 信息窗口高度
								title : "信息窗口" , // 信息窗口标题
								enableMessage:true//设置允许信息窗发送短息
							   };
						for(var i=0;i<json.length;i++){
							//var marker = new BMap.Marker(new BMap.Point(json[i].lng,json[i].lat));  // 创建标注
							var myIcon = new BMap.Icon("http://developer.baidu.com/map/jsdemo/img/fox.gif", new BMap.Size(300,157));
							var marker = new BMap.Marker(pt,{icon:myIcon});  // 创建标注
							var content = json[i].name;
							map.addOverlay(marker);               // 将标注添加到地图中
							addClickHandler(content,marker);
						}
						loadflag(opts,json[0].id);
					}
                }  
              });
		}
	function loadjsonflag(){
		$.getJSON("../resources/dealerinfojson.json",function(data){
			var json =data;
					opts = {
							width : 310,     // 信息窗口宽度
							height: 125,     // 信息窗口高度
							title : "信息窗口" , // 信息窗口标题
							enableMessage:true//设置允许信息窗发送短息
						   };
					  var options = {
					            size: BMAP_POINT_SIZE_BIG,
					            shape: BMAP_POINT_SHAPE_STAR,
					            color: '#d340c3'
					        }
					var txt = "";
					  var points = [];
					  var content ="";
					  //alert(""+json.length);
					for(var i=0;i<json.length;i++){
						
						if(json[i].result=="true"){
							 
							   content = "<div style='line-height:1.8em;font-size:14px;'>企业名称："+json[i].name+"<br>";
								content += "所属城市："+json[i].chengshmch+"<br>";
								content += "买卖类型："+json[i].maimlx+"<br>";
								content += "地址："+json[i].address+"</div>"; 
								  var p = new BMap.Point(json[i].lng,json[i].lat);  
						          p.data = content;  
						          points.push(p);  
						} 
						
					}
					 
					   var pointCollection = new BMap.PointCollection(points, options);  // 初始化PointCollection
					   pointCollection.addEventListener('click', function (e) {
					         // alert(e.point.data);  // 监听点击事件
					          var infoWindow = new BMap.InfoWindow(e.point.data);    // 创建信息窗口对象
						         map.openInfoWindow(infoWindow,e.point); 
					        });
					        map.addOverlay(pointCollection);  // 添加Overlay
		});
	}		
		function loadjsonflag1(){
			$.getJSON("../resources/dealerinfojson.json",function(data){
				var json =data;
						opts = {
								width : 310,     // 信息窗口宽度
								height: 125,     // 信息窗口高度
								title : "信息窗口" , // 信息窗口标题
								enableMessage:true//设置允许信息窗发送短息
							   };
						var txt = "";
						 //alert(""+json.length);
						for(var i=0;i<json.length;i++){
							
							if(json[i].result=="true"){
								
								//var marker = new BMap.Marker(new BMap.Point(json[i].lng,json[i].lat));  // 创建标注
								var myIcon = new BMap.Icon("../resources/map/img/sc_b.png", new BMap.Size(30,30));
								var marker = new BMap.Marker(new BMap.Point(json[i].lng,json[i].lat),{icon:myIcon});  // 创建标注
								var content = "企业名称："+json[i].name+"<br>";
								content += "所属城市："+json[i].chengshmch+"<br>";
								content += "买卖类型："+json[i].maimlx+"<br>";
								content += "地址："+json[i].address;
								//marker.enableDragging();
								map.addOverlay(marker);               // 将标注添加到地图中
								addClickHandler(content,marker);
							}else{
								txt += json[i].name+" || ";
							}
							
						}
						$("#falseload").val(txt);
						
			});
		}
		
		function cx(){
			 
			$.ajax( {
			    type : "POST",
			    dataType: "json",
			    url : "<s:url value="/"/>baidumapcontroller/getDealerMapList",  
			    data: {}, 
			    success : function(data){ 
			    	 
			    	var json =data;
					opts = {
							width : 310,     // 信息窗口宽度
							height: 125,     // 信息窗口高度
							title : "信息窗口" , // 信息窗口标题
							enableMessage:true//设置允许信息窗发送短息
						   };
					  var options = {
					            size: BMAP_POINT_SIZE_NORMAL,
					            shape: BMAP_POINT_SHAPE_CIRCLE,
					            color: '#d340c3'
					        }
					var txt = "";
					  var points = [];
					  var content ="";
					  //alert(""+json.length);
					for(var i=0;i<json.length;i++){
						
						 
							 
							   content = "<div style='line-height:1.8em;font-size:14px;'>企业名称："+json[i].fullname+"<br>";
								content += "所属城市："+json[i].chengshmch+"<br>";
								content += "买卖类型："+json[i].maimlx+"<br>";
								content += "地址："+json[i].address+"</div>"; 
								  var p = new BMap.Point(json[i].lng,json[i].lat);  
						          p.data = content;  
						          points.push(p);  
						 
						
					}
					 
					   var pointCollection = new BMap.PointCollection(points, options);  // 初始化PointCollection
					   pointCollection.addEventListener('click', function (e) {
					         // alert(e.point.data);  // 监听点击事件
					          var infoWindow = new BMap.InfoWindow(e.point.data);    // 创建信息窗口对象
						         map.openInfoWindow(infoWindow,e.point); 
					        });
					        map.addOverlay(pointCollection);  // 添加Overlay 
			    },
			    error : function()
			    {
			        alert("加载失败");
			    }
			});
		}		
</script>

</body>
</html>
